<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册登录界面</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css">
<link rel="stylesheet" href="./style.css">
</head>
<body>
<div class="container right-panel-active">
    <!-- 注册 -->
    <div class="container_form container--signup">
        <form action="#" class="form" id="form1">
            <h2 class="form_title">Sign Up</h2>
            <input type="text" placeholder="User" class="input" />
            <input type="email" placeholder="Email" class="input" />
            <input type="password" placeholder="Password" class="input" />
            <button class="btn">Sign Up</button>
        </form>
    </div>

    <!-- 登录 -->
    <div class="container_form container--signin">
        <form action="#" class="form" id="form2">
            <h2 class="form_title">Sign In</h2>
            <!-- <input type="email" placeholder="Email" class="input" /> -->
            <input type="username" placeholder="User" class="input" id="username"/>
            <input type="password" placeholder="Password" class="input" id="password"/>
            <a href="#" class="link">Forgot your password?</a>
            <button class="btn">Sign In</button>
        </form>
    </div>

    <!-- 浮层 -->
    <div class="container_overlay">
        <div class="overlay">
            <div class="overlay_panel overlay--left">
                <button class="btn" id="signIn">Sign In</button>
            </div>
            <div class="overlay_panel overlay--right">
                <button class="btn" id="signUp">Sign Up</button>
            </div>
        </div>
    </div>
</div>

<!-- 背景 -->
<div class="slidershow">
    <div class="slidershow--image" style="background-image: url('https://source.unsplash.com/Snqdjm71Y5s')"></div>
    <div class="slidershow--image" style="background-image: url('https://source.unsplash.com/5APj-fzKE-k')"></div>
    <div class="slidershow--image" style="background-image: url('https://source.unsplash.com/wnbBH_CGOYQ')"></div>
    <div class="slidershow--image" style="background-image: url('https://source.unsplash.com/OkTfw7fXLPk')"></div>
</div>

<!-- partial -->
  <script src="./script.js"></script>

  <script>
    import axios from 'axios'
    import md5 from 'js-md5'
    
    export default {
      created () {
        this.username = this.$route.query.name
      },
      data () {
        return {
          username: "",
          password: "",
          errMsg: {
            password: '',
            username: '',
          },
          usernameRules: [{
            required: true,
            message: '请输入用户名',
            trigger: 'onBlur'
          }],
          passwordRules: [{
            required: true,
            message: '请输入密码',
            trigger: 'onBlur'
          }]
        }
      },
      methods: {
        onSubmit (values) {
          axios({
            url: " https://db-api.amarea.cn/users",
            method: "GET",
          }).then(res => {
            console.log(res.data);
            res.data.forEach((item) => {
              if (item.id === values.username && item.password === md5(values.password)) {
                this.$router.push({
                  path: "/home",
                  query: {
                    name: values.username
                  }
                })
              } else {
                this.errMsg.password = '用户名或密码错误'
              }
            });
          })
        },
      },
    }
    </script>

    
    
</body>
</html>